package logview;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static transient final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(ListServlet.class);
	private String rp;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		final Properties p = new Properties();
		try {
			p.load(new FileInputStream(rp));
		} catch (Exception e) {
			throw new ServletException("Error loading properties: "+e);
		}
		req.setAttribute("Map", p);
		req.getRequestDispatcher("/list.jsp").forward(req, resp);
	}

	@Override
	public void init(ServletConfig config) throws ServletException {
		log.debug(ListServlet.class.getName()+" initialized");
		this.rp = config.getServletContext().getRealPath("WEB-INF/logfiles.properties");
	}
	
	@Override
	public void destroy() {
		log.debug(ListServlet.class.getName()+" destroyed");
		super.destroy();
	}
}
